const router = require('express').Router()
const db = require('../db.config')

// 中国标准时间 转换成 年月日
function formatDateTime(datestr) {

    let date = new Date(datestr)

    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    var minute = date.getMinutes();
    minute = minute < 10 ? ('0' + minute) : minute;
    // return y + '-' + m + '-' + d+' '+h+':'+minute;
    return y + '-' + m + '-' + d
}


router.get('/editstudent', (req, res) => {
    let { id, name,date, address } = req.query

    let formatdate = formatDateTime(date)
//  UPDATE table_name
// SET column1=value1,column2=value2,...
// WHERE some_column=some_value;
// 123
    console.log(req.query);
    console.log(id);
    let sql = `UPDATE students SET name='${name}',date='${formatdate}',address='${address}'  WHERE id=${id}`
    db.query(sql, (err, data) => {
        res.send({
            code: 200,
            success: "修改成功"
        })
    })
})
module.exports = router